namespace SimpleWebServices.Web.UI.Html.Elements
{
    using System.Xml.Serialization;
    using SimpleWebServices;
    using Xunit;

    public sealed class InlineFrameFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<InlineFrame>()
                .DerivesFrom<InnerElements>()
                .IsConcreteClass()
                .IsUnsealed()
                .HasDefaultConstructor()
                .Implements<IXmlSerializable>()
                .XmlRoot("iframe")
                .Result);
        }

        [Fact]
        public void deserialize()
        {
            InlineFrame expected = new InlineFrame
            {
                Id = "id",
                Class = "class",
                Language = "fr",
                Title = "title",
                Elements =
                {
                    new TextString("Some text")
                }
            };

            string xml = "<iframe id='id' class='class' lang='fr' title='title'>Some text</iframe>";
            InlineFrame actual = xml.Deserialize<InlineFrame>();

            Assert.Equal<string>(expected.ToString(), actual.ToString());
        }

        [Fact]
        public void deserializeEmpty()
        {
            Assert.NotNull("<iframe />".Deserialize<InlineFrame>());
        }

        [Fact]
        public void serialize()
        {
            InlineFrame obj = new InlineFrame
            {
                Id = "id",
                Class = "class",
                Language = "fr",
                Title = "title",
                Elements =
                {
                    new TextString("Some text")
                }
            };

            string xpath = "1=count(/iframe[@id='id'][@class='class'][@lang='fr'][@title='title'][text()='Some text'])";

            Assert.True((bool)obj.Serialize().CreateNavigator().Evaluate(xpath));
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new InlineFrame());
        }

        [Fact]
        public void prop_Alignment()
        {
            Assert.True(new PropertyExpectations(typeof(InlineFrame).GetProperty("Alignment"))
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void prop_FrameBorder()
        {
            Assert.True(new PropertyExpectations(typeof(InlineFrame).GetProperty("FrameBorder"))
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void prop_Height()
        {
            Assert.True(new PropertyExpectations(typeof(InlineFrame).GetProperty("Height"))
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void prop_LongDescription()
        {
            Assert.True(new PropertyExpectations(typeof(InlineFrame).GetProperty("LongDescription"))
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void prop_MarginHeight()
        {
            Assert.True(new PropertyExpectations(typeof(InlineFrame).GetProperty("MarginHeight"))
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void prop_MarginWidth()
        {
            Assert.True(new PropertyExpectations(typeof(InlineFrame).GetProperty("MarginWidth"))
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void prop_Name()
        {
            Assert.True(new PropertyExpectations(typeof(InlineFrame).GetProperty("Name"))
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void prop_Scrolling()
        {
            Assert.True(new PropertyExpectations(typeof(InlineFrame).GetProperty("Scrolling"))
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void prop_Source()
        {
            Assert.True(new PropertyExpectations(typeof(InlineFrame).GetProperty("Source"))
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void prop_Width()
        {
            Assert.True(new PropertyExpectations(typeof(InlineFrame).GetProperty("Width"))
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void op_Deserialize_string_string_string()
        {
            InlineFrame expected = new InlineFrame
            {
                Id = "id",
                Class = "class",
                Language = "fr",
                Title = "title",
                Alignment = "left",
                FrameBorder = "1",
                Height = "50%",
                LongDescription = "http://example.com/description",
                MarginHeight = "1",
                MarginWidth = "1",
                Name = "name",
                Scrolling = "auto",
                Source = "http://example.com/source",
                Width = "90%"
            };

            string xml = 
                "<iframe" +
                " id='id'" +
                " class='class'" +
                " lang='fr'" +
                " title='title'" +
                " align='left'" +
                " frameborder='1'" +
                " height='50%'" +
                " longdesc='http://example.com/description'" +
                " marginheight='1'" +
                " marginwidth='1'" +
                " name='name'" +
                " scrolling='auto'" +
                " src='http://example.com/source'" +
                " width='90%'" +
                "/>";
            InlineFrame actual = new InlineFrame().Deserialize("iframe", null, xml) as InlineFrame;

            Assert.Equal<string>(expected.ToString(), actual.ToString());
        }
    }
}